package com.yike.user.service.impl;

import com.yike.user.entity.ShopCount;
import com.yike.user.mapper.ShopCountMapper;
import com.yike.user.service.ShopCountService;
import com.yike.user.param.ShopCountPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 店铺统计表 服务实现类
 *
 * @author Sakura
 * @since 2024-11-13
 */
@Slf4j
@Service
public class ShopCountServiceImpl extends BaseServiceImpl<ShopCountMapper, ShopCount> implements ShopCountService {

    @Autowired
    private ShopCountMapper shopCountMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveShopCount(ShopCount shopCount) throws Exception {
        return super.save(shopCount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateShopCount(ShopCount shopCount) throws Exception {
        return super.updateById(shopCount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteShopCount(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<ShopCount> getShopCountPageList(ShopCountPageParam shopCountPageParam) throws Exception {
        Page<ShopCount> page = new PageInfo<>(shopCountPageParam, OrderItem.desc(getLambdaColumn(ShopCount::getCreateTime)));
        LambdaQueryWrapper<ShopCount> wrapper = new LambdaQueryWrapper<>();
        IPage<ShopCount> iPage = shopCountMapper.selectPage(page, wrapper);
        return new Paging<ShopCount>(iPage);
    }

}
